#!/bin/bash
echo "授予 java 执行权限"
chmod +x /opt/apps/com.tfswx.xunwen-jietu/files/jdk/bin/java

echo "开始创建桌面图标"
install_launcher_all_users() {
  getent passwd | while IFS=: read -r name password uid gid gecos home shell; do
    if [ -z "$shell" ] || [ "$shell" = "/bin/false" ] || [ "$shell" = "/usr/sbin/nologin" ]; then
      continue
    fi
    if [ ! -d "$home" ] || [ "$(stat -c %u "$home")" != "$uid" ]; then
      continue
    fi
    home_user_dirs="$home/.config/user-dirs.dirs"
    if [ ! -f "$home_user_dirs" ]; then
      continue
    fi
    home_user_dirs="$home$(grep XDG_DESKTOP_DIR= $home_user_dirs |
      cut -d '=' -f 2- |
      sed 's/^"$HOME\(.*\)"$/\1/')"
    if [ ! -d "$home_user_dirs" ]; then
      continue
    fi
    install -m 755 -o "$uid:$gid" "/usr/share/applications/${1}" "$home_user_dirs"
    echo "创建快捷图标 $home_user_dirs"
  done
}

install_launcher_all_users "com.tfswx.xunwen-jietu.desktop"
echo "桌面图标创建结束"
